/**
 * 
 */
package No401_500.No461_470.HammingDistance_461;
/** 
 * @author  作者 E-mail: ttljtw@qq.com
 * @date 创建时间：2017年2月18日 下午9:31:14 
 * @version 1.0 
 * @parameter  
 * @since  
 * @return  
 */
/**
 * @author 李敬
 *
 */
public class Solution {

    public int hammingDistance1(int x, int y) {
    	int distance = 0;
    	int[] x1 = new int[32];
    	for (int i = 0; i < 32; i++) {
			if (x != 0) {
				x1[i] = x%2;
				x = x/2;
			}else {
				x1[i] = 0;
			}
			if (y%2 != x1[i]) {
				distance++;
			}
			y = y/2;
		}
    	
		return distance;
        
    }
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Solution solution = new Solution();
		System.out.println(solution.hammingDistance(1, 4));
	}
	private int hammingDistance(int x, int y) {
		// TODO Auto-generated method stub
		int distance = 0;
		int temp = x^y;
		String a = Integer.toBinaryString(temp);
		for (int i = 0; i < a.length(); i++) {
			if (a.charAt(i)=='1') {
				distance++;
			}
		}
//		for (Character character : a.toCharArray()) {
//			if (character.equals('1')) {
//				distance++;
//			}
//		}
		return distance;
	}

}
